Skip to content

Add button type to updatemenus #974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 26, 2016
Merged

Add button type to updatemenus #974

merged 11 commits into from
Sep 26, 2016

Conversation

rreusser
Copy link
Contributor

@rreusser rreusser commented Sep 22, 2016

This PR adds the following attributes to updatemenus:

  • type: 'buttons'/'dropdown': if true, is buttons instead of dropdown
  • direction: 'left'/'right'/'up'/'down': affects which way the buttons extend, though they're still ordered l-to-r or top-to-bottom. It's not inconceivable to auto-detect this when the menu would otherwise go off-screen, but I think less magic is better.
  • showactive: boolean. Shows active state if true. Set to false to turn the buttons into plain non-stateful buttons.

See live example at: http://rickyreusser.com/animation-experiments/#updatemenus

Notably, this PR does not implement scrolling for overflow. 😞

@etpinard etpinard added this to the v1.18.0 milestone Sep 23, 2016
dflt: false,
description: [
'For dropdown menus, opens the menu in the reverse direction'
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👓 missing .join(' ')

Copy link
Contributor Author

@rreusser rreusser Sep 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks! Yes, noticed that the tests seem to check for that :)

description: [
'Determines whether the menu and buttons are laid out vertically',
'or horizontally'
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another missing .join(' ')

@@ -57,6 +57,37 @@ module.exports = {
].join(' ')
},

openreverse: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not fully in ❤️ with this attribute name, but I can't think of anything else.

Maybe @cldougl could help.

with openreverse: false buttons drop down (or to the right)

image

with openreverse: true the buttons drop up (or to the left)

image

Copy link
Contributor Author

@rreusser rreusser Sep 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about expandreverse.

Copy link
Member

@cldougl cldougl Sep 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have to be a boolean (t/f)? My initial thought is that it may be more clear if it's called something with direction or dropdowndirection/expanddirection then have options up / down

For me, the reverse is a tiny bit confusing because I think of the options being in a reversed order rather than the dropdown opening up vs down.

Copy link
Contributor Author

@rreusser rreusser Sep 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default is to the right, if horizontal, or down, if vertical. Hence 'reverse' instead of just up/down since the need for left/right would then be modal.

Copy link
Contributor Author

@rreusser rreusser Sep 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh… maybe orientation should encode both? The problem is that we have two orientations but four directions. What about orientation: 'l'|'r'|'u'|'d' instead of 'h'|'v'. Or direction instead of orientation, if necessary for consistency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the 'l'|'r'|'u'|'d' set of options.

But to avoid confusion, I wouldn't call the attribute orientation (as orientation is already used for legends, bar ...).

Maybe direction: 'l'|'r'|'u'|'d' ?

Copy link
Member

@cldougl cldougl Sep 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see! (sorry for the confusion w/ the sideway opening, didn't realize that was an option)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for direction
I like the explicitness of 'l'|'r'|'u'|'d' over true|false

Copy link
Contributor

@etpinard etpinard Sep 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we spell left and right when specifying text anchors, so let's go with:

direction: 'left'|'right'|'up'|'down'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to direction: 'left'|'right'|'up'|'down'. Waiting for tests to pass.

drawButtons(gd, gHeader, gButton, menuOpts);
}
} else {
drawButtons(gd, gHeader, null, menuOpts);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very lovely way to reuse the existing logic. Thanks!

I hope my code wasn't too hard to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope! It was pretty straightforward. Was kinda able to shoehorn my needs into it, as you've seen.

@@ -181,8 +191,8 @@ function drawHeader(gd, gHeader, gButton, menuOpts) {
.text('▼');
Copy link
Contributor

@etpinard etpinard Sep 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could add some logic for that character around orientation and openreverse.

For example, orientation: 'h' / openreverse: true would put some ◀️ character to the left of the header text. orientation: 'v' / openreverse: ture would put some ⬆️ character etc.

Copy link
Contributor Author

@rreusser rreusser Sep 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought about that. I had mixed feelings. I'm not opposed to it. For comparison, system select menus look like this when near the bottom of the screen.

2016-09-23 11 53 55

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no strong opinion about it.

Let's ask @jackparmer and @delekru

@@ -313,7 +363,7 @@ function styleButtons(buttons, menuOpts) {
buttons.each(function(buttonOpts, i) {
var button = d3.select(this);

if(i === active) {
if(i === active && menuOpts.showactive) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice


// Store per-item sizes since a row of horizontal buttons, for example,
// don't all need to be the same width:
menuOpts.widths[i] = wEff;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice. I think now this exact same findDimensions routine could be use for RangeSelectors - that will be for a future PR though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Yeah, I had to do some carefully wacky stuff to get it to handle all the cases (h/v, buttons/dropdown, reverse/nonreverse, anchor=t/b/l/r—which is at least no less than like 2^5 = 32 cases), but I think it works…

@rreusser
Copy link
Contributor Author

Fixed image mock (floating point pixel discrepancy; modified for alignment purposes). And added a pretty deluxe new one. Doesn't test opened menus, but I like it anyway. At least sets up difficult-to-mock extras for easy verification in dashboard.

updatemenus_positioning

@rreusser
Copy link
Contributor Author

rreusser commented Sep 23, 2016

@etpinard the majority of the code went toward positioning so that the image mock tests the majority of what's implemented here. I could add more tests, but I think it'd only be redundant and more code to maintain. Other than that, I think this is ready for review.

For simplicity in reviewing, you can see an update-to-date use that's nearly identical to the mock here: http://rickyreusser.com/animation-experiments/#updatemenus

@@ -43,12 +43,12 @@ module.exports = function draw(gd) {
* <g item header />
* <text item header-arrow />
* <g header-group />
* <g item header />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AHHHH stupid vim plugin. It mangles html tags when you scroll incorrectly… restoring these.

@etpinard
Copy link
Contributor

💃 This looks amazing

@rreusser can you update the introduction comment block for future reference to this PR (it's still showing openreverse and orientation). Thanks!

As a side note, I'm kind of kicking myself for not naming the update menu buttons attribute items instead, having { type: 'buttons', buttons: [{ }, /* */] } looks a little weird. But, I guess it's not the end of the world.

@etpinard etpinard mentioned this pull request Sep 26, 2016
@etpinard
Copy link
Contributor

Oh and by the way, I added #974 (comment) to #810 - if ever we decide to implement it in the future.

@rreusser
Copy link
Contributor Author

@etpinard yeah, backwards compatibility can be a burden! It's always possible to move to a new syntax and very slowly deprecate the old, but I think this is fine for the foreseeable future.

@rreusser rreusser merged commit 7cc1e6b into master Sep 26, 2016
@rreusser rreusser deleted the updatemenus-type branch September 26, 2016 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants